package de.mhus.lib.core;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

public class MDate extends Date {

	public MDate() {
		super();
	}

	public MDate(long date) {
		super(date);
	}

	public MDate(Timestamp timestamp) {
		this(timestamp.getTime());
	}

	public MDate(String string) {
		Date date = MCast.toDate(string, null);
		this.setTime(date.getTime());
	}

	public String toString() {
		return MCast.toIsoDate(this);
	}

	public java.sql.Date toSqlDate() {
		return new java.sql.Date(getTime());
	}

	public Time toSqlTime() {
		return new java.sql.Time(getTime());
	}

	public Timestamp toSqlTimestamp() {
		return new java.sql.Timestamp(getTime());
	}

	public Calendar toCalendar() {
		return MCast.toCalendar(this);
	}

	public static boolean isEarlierAs(Date a, Date b) {
		return a.compareTo(b) < 0;
	}
	
	public static boolean isLaterAs(Date a, Date b) {
		return a.compareTo(b) > 0;
	}
	
}
